<?php

namespace app\api\model;

use app\common\enums\StatusEnum;

class LangClassLessonReciteAnswer extends \app\common\model\LangClassLessonReciteAnswer
{
    /**
     * 背诵单词或者句子的答案
     * @param $reciteIds
     * @return array
     * @throws \think\Exception\DbException
     */
    public static function getListByRecite($reciteIds)
    {
        $model = static::field('id AS answerId, recite_id AS reciteId, answer, image, is_right AS isRight')
            ->where('recite_id', 'in', $reciteIds)
            ->where(['status' => StatusEnum::ENABLED])
            ->order(['sort_num' => 'desc', 'create_time' => 'desc'])
            ->select()
            ->toArray();
        $result = [];
        foreach ($model as $key => $value) {
            // 第几个
            $value['sorting'] = $key + 1;
            $result[$value['reciteId']][] = [
                'answerId' => $value['answerId'],
                'answer' => $value['answer'],
                'image' => $value['image'] ? config('file_prefix') . $value['image'] : '',
                'isRight' => $value['isRight'],
                'sorting' => $value['sorting']
            ];
        }
        return $result;
    }
}